package com.github.xiaolyuh.enums;

public enum CacheCodeEnum {

    //调用成功
    SUCCESS(0, 0, "success"),
    //系统内部异常，请联系管理员
    FAIL(1, 52000, "failed"),
    //参数输入无效
    PARAM_INVALID(0, 59999, "invalid params"),
    C_COUPON_NOT_FOUND(0, 52146, "券不存在"),
    C_COUPON_INVALID(0, 52147, "非有效券"),
    C_COUPON_OUT_OF_DATE(0, 52148, "券已过期"),
    C_FLUSH_REDIS_CACHE(0, 52149, "券刷新缓存异常"),
    A_INDEX_FLUSH_CACHE(0, 52150, "活动索引类型不支持"),
    SEND_MSG_ERROR(1,52151,"Redis消息发送失败"),
    ;

    // 0-无需告警 1-需要告警
    private int type;

    // 返回码
    private int code;

    // 返回码描述
    private String text;

    CacheCodeEnum(int type, int code, String text) {
        this.type = type;
        this.code = code;
        this.text = text;
    }

    public int getType() {
        return type;
    }

    public int getCode() {
        return code;
    }

    public String getText() {
        return text;
    }

    public static int getType(int code) {
        CacheCodeEnum[] codeEnumsArr = CacheCodeEnum.values();
        for (CacheCodeEnum codeEnum : codeEnumsArr) {
            if (codeEnum.getCode() == code) {
                return codeEnum.getType();
            }
        }
        return 1;
    }
}